/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.emftext.language.office.office.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;

import org.emftext.language.office.office.Employee;
import org.emftext.language.office.office.Office;
import org.emftext.language.office.office.OfficePackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Employee</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.emftext.language.office.office.impl.EmployeeImpl#getWorksIn <em>Works In</em>}</li>
 *   <li>{@link org.emftext.language.office.office.impl.EmployeeImpl#getWorksWith <em>Works With</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class EmployeeImpl extends OfficeElementImpl implements Employee
{
  /**
   * The cached value of the '{@link #getWorksIn() <em>Works In</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getWorksIn()
   * @generated
   * @ordered
   */
  protected Office worksIn;

  /**
   * The cached value of the '{@link #getWorksWith() <em>Works With</em>}' reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getWorksWith()
   * @generated
   * @ordered
   */
  protected EList<Employee> worksWith;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected EmployeeImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return OfficePackage.Literals.EMPLOYEE;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Office getWorksIn()
  {
    if (worksIn != null && worksIn.eIsProxy())
    {
      InternalEObject oldWorksIn = (InternalEObject)worksIn;
      worksIn = (Office)eResolveProxy(oldWorksIn);
      if (worksIn != oldWorksIn)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, OfficePackage.EMPLOYEE__WORKS_IN, oldWorksIn, worksIn));
      }
    }
    return worksIn;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Office basicGetWorksIn()
  {
    return worksIn;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setWorksIn(Office newWorksIn)
  {
    Office oldWorksIn = worksIn;
    worksIn = newWorksIn;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, OfficePackage.EMPLOYEE__WORKS_IN, oldWorksIn, worksIn));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Employee> getWorksWith()
  {
    if (worksWith == null)
    {
      worksWith = new EObjectResolvingEList<Employee>(Employee.class, this, OfficePackage.EMPLOYEE__WORKS_WITH);
    }
    return worksWith;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case OfficePackage.EMPLOYEE__WORKS_IN:
        if (resolve) return getWorksIn();
        return basicGetWorksIn();
      case OfficePackage.EMPLOYEE__WORKS_WITH:
        return getWorksWith();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case OfficePackage.EMPLOYEE__WORKS_IN:
        setWorksIn((Office)newValue);
        return;
      case OfficePackage.EMPLOYEE__WORKS_WITH:
        getWorksWith().clear();
        getWorksWith().addAll((Collection<? extends Employee>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case OfficePackage.EMPLOYEE__WORKS_IN:
        setWorksIn((Office)null);
        return;
      case OfficePackage.EMPLOYEE__WORKS_WITH:
        getWorksWith().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case OfficePackage.EMPLOYEE__WORKS_IN:
        return worksIn != null;
      case OfficePackage.EMPLOYEE__WORKS_WITH:
        return worksWith != null && !worksWith.isEmpty();
    }
    return super.eIsSet(featureID);
  }

} //EmployeeImpl
